﻿namespace OA.Repository.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class init : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.SysActions",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        ParentId = c.Int(nullable: false),
                        Title = c.String(nullable: false, maxLength: 20),
                        ControllerName = c.String(maxLength: 20),
                        ActionName = c.String(maxLength: 20),
                        HttpMethod = c.String(maxLength: 20),
                        Url = c.String(maxLength: 20),
                        Icon = c.String(maxLength: 20),
                        IsMenu = c.Boolean(nullable: false),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.SysRoles",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false, maxLength: 20),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.Sys_users",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        LoginName = c.String(nullable: false, maxLength: 50),
                        LoginPwd = c.String(nullable: false, maxLength: 50),
                        PersonId = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.SysPersons", t => t.PersonId, cascadeDelete: true)
                .Index(t => t.PersonId);
            
            CreateTable(
                "dbo.SysPersons",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false, maxLength: 20),
                        Gender = c.String(nullable: false, maxLength: 2),
                        Phone = c.String(nullable: false, maxLength: 20),
                        OrgId = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.SysOrgs", t => t.OrgId, cascadeDelete: true)
                .Index(t => t.OrgId);
            
            CreateTable(
                "dbo.SysOrgs",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false, maxLength: 20),
                        ParentId = c.Int(nullable: false),
                        Description = c.String(maxLength: 50),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.SysPositions",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.SysRoleSysActions",
                c => new
                    {
                        SysRole_Id = c.Int(nullable: false),
                        SysAction_Id = c.Int(nullable: false),
                    })
                .PrimaryKey(t => new { t.SysRole_Id, t.SysAction_Id })
                .ForeignKey("dbo.SysRoles", t => t.SysRole_Id, cascadeDelete: true)
                .ForeignKey("dbo.SysActions", t => t.SysAction_Id, cascadeDelete: true)
                .Index(t => t.SysRole_Id)
                .Index(t => t.SysAction_Id);
            
            CreateTable(
                "dbo.SysUserSysRoles",
                c => new
                    {
                        SysUser_Id = c.Int(nullable: false),
                        SysRole_Id = c.Int(nullable: false),
                    })
                .PrimaryKey(t => new { t.SysUser_Id, t.SysRole_Id })
                .ForeignKey("dbo.Sys_users", t => t.SysUser_Id, cascadeDelete: true)
                .ForeignKey("dbo.SysRoles", t => t.SysRole_Id, cascadeDelete: true)
                .Index(t => t.SysUser_Id)
                .Index(t => t.SysRole_Id);
            
        }
        
        public override void Down()
        {
            DropForeignKey("dbo.SysUserSysRoles", "SysRole_Id", "dbo.SysRoles");
            DropForeignKey("dbo.SysUserSysRoles", "SysUser_Id", "dbo.Sys_users");
            DropForeignKey("dbo.Sys_users", "PersonId", "dbo.SysPersons");
            DropForeignKey("dbo.SysPersons", "OrgId", "dbo.SysOrgs");
            DropForeignKey("dbo.SysRoleSysActions", "SysAction_Id", "dbo.SysActions");
            DropForeignKey("dbo.SysRoleSysActions", "SysRole_Id", "dbo.SysRoles");
            DropIndex("dbo.SysUserSysRoles", new[] { "SysRole_Id" });
            DropIndex("dbo.SysUserSysRoles", new[] { "SysUser_Id" });
            DropIndex("dbo.SysRoleSysActions", new[] { "SysAction_Id" });
            DropIndex("dbo.SysRoleSysActions", new[] { "SysRole_Id" });
            DropIndex("dbo.SysPersons", new[] { "OrgId" });
            DropIndex("dbo.Sys_users", new[] { "PersonId" });
            DropTable("dbo.SysUserSysRoles");
            DropTable("dbo.SysRoleSysActions");
            DropTable("dbo.SysPositions");
            DropTable("dbo.SysOrgs");
            DropTable("dbo.SysPersons");
            DropTable("dbo.Sys_users");
            DropTable("dbo.SysRoles");
            DropTable("dbo.SysActions");
        }
    }
}
